package controller.users;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.*;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class RegisterForm extends ActionForm {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer id;
	private String name;
	private String firstname;
	private String mail;
	private String pass;
	private boolean role_id;
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getFirstname() {
		return firstname;
	}

	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}

	public String getMail() {
		return mail;
	}

	public void setMail(String mail) {
		this.mail = mail;
	}

	public String getPass() {
		return pass;
	}

	public void setPass(String pass) {
		this.pass = pass;
	}
	
	public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
		  ActionErrors errors = new ActionErrors();

		  if ((name == null) || (name.length() == 0))
		    errors.add("name", new ActionMessage("erreur.name.obligatoire"));

		  if ((firstname == null) || (firstname.length() == 0))
		    errors.add("firstname", new ActionMessage("erreur.firstname.obligatoire"));
		  
		  if ((pass == null) || (pass.length() == 0))
			    errors.add("pass", new ActionMessage("erreur.pass.obligatoire"));
		  
		  if ((mail == null) || (mail.length() == 0))
			    errors.add("mail", new ActionMessage("erreur.mail.obligatoire"));

		  return errors;
	}

	public boolean isRole() {
		return role_id;
	}

	public void setRole(boolean role) {
		this.role_id = role;
	}
}
